import { ApiProperty, IntersectionType, PartialType } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  IsOptional,
  IsString,
  MinLength,
  IsArray,
  IsEnum,
  IsNumber,
} from 'class-validator';
import { CommentStatus } from '~/shared/mongodb/schema/comment.schema';
import { PagerDto } from '~/common/dto/pager.dto';

export class CreateCommentDto {
  @ApiProperty({ description: '用户头像' })
  @IsString()
  @IsOptional()
  userAvatar?;

  @ApiProperty({ description: '用户名称' })
  @IsString()
  userName: string = '匿名用户';

  @ApiProperty({ description: '评论内容' })
  @IsString()
  @MinLength(1, { message: '评论内容不能为空' })
  content: string;

  @ApiProperty({ description: '评分' })
  @IsNumber()
  score: number;

  @ApiProperty({
    description: '评论图片URL数组，最多3张',
    required: false,
    type: [String],
  })
  @IsOptional()
  @IsArray()
  @IsString({ each: true, message: '图片URL必须是字符串' })
  images?: string[];

  @ApiProperty({ description: '关联的商品ID' })
  @IsString()
  productId: string;
}

export class QueryCommentDto extends PagerDto {
  @ApiProperty({ description: '商品ID' })
  @IsOptional()
  productId?: string;

  @ApiProperty({ description: '评论状态', enum: CommentStatus })
  @IsOptional()
  @IsEnum(CommentStatus)
  status?: CommentStatus;

  @ApiProperty({ description: '用户名称（模糊查询）' })
  @IsOptional()
  userName?: string;
}

export class UpdateCommentDto extends PartialType(CreateCommentDto) {
  @ApiProperty({ description: '评论状态', enum: CommentStatus })
  @IsOptional()
  @IsEnum(CommentStatus)
  status?: CommentStatus;
}
